#include "stdafx.h"
#include "Main.h"

LoadingScreen LS;
Memc<AI> AIs;
Game::ObjMemx<Game::Static> Statics; // container for static objects
Game::ObjMemx<Player            > Players;
Game::ObjMemx<Game::ObjLightCone> Lights;
Game::ObjMemx<Game::ObjParticles> Particles1;
Game::ObjMemx<Game::Item        > Items;
Edit::EnvironmentOptions env;
bool InitGame()
{
	Physics.create(CSS_NONE, true, "../Installation/PhysX");

	Sun.image=Images("gfx/sky/sun.gfx");
    Sky.atmospheric();
	Ms.hide();
	Game::World.init()
			   .setObjType(Players, OBJ_PLAYER)
			   .setObjType(Items  , OBJ_ITEM  )
			   .setObjType(Lights, OBJ_LIGHT_CONE)
			   .setObjType(Particles1, OBJ_PARTICLES)
			   .setObjType(Statics,OBJ_STATIC)
	           .New("World/Sample.world");

	env.loadTxt("Clouds/Night.environment.txt");

	Cam.setSpherical(Vec(0,0,0), -PI_4, -0.5f, 0, 10).set(); // set initial camera
	AIs.New().create("Monster1.txt");
	return true;
} 
bool UpdateGame()
{

    if(LS.update())
    {
	   return true; // this needs to be at the start of 'Update' function
    }
    if(!Game::World.updated()) // if current world hasn't yet been updated, it means it's a new or load game, so let background loader handle it
    {
      LS.start(); // create background loader
    }
	REPA(Players)Players[i].camera();
	
	REPA(AIs)AIs[i].update();
	Game::World.update(Cam.at);
	if(Kb.bp(KB_F1)){OptionsToggle();Ms.toggle();}
	Gui.update();
	return true;
}
void ShutGame()
{
	LS.del();
}
void Render()
{
	Game::World.draw();
	switch(Renderer())
	{
		case RM_PREPARE : {REPA(AIs)AIs[i].Draw();}
	}
}
void DrawGame()
{
   if(LS.draw())return; // this needs to be at the start of 'Draw' function
   Renderer(Render);
   REPA(Players)Players[i].CrossHair();
   Gui.draw();
   REPA(Players)D.text(-1,-0.95,S+"Health: "+(Int)Players[i].HealthPoints);
   if(Players.elms())if(!Players[0].Alive())D.text(0,0,"You're dead");
}

State GameState(UpdateGame,DrawGame,InitGame,ShutGame);